home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 September / macformat-028.iso / mac / Shareware City / Developers / BoxMaker++ / Touch ƒ / touchshell.cp < prev    next >
Encoding:
Text File  |  1995-06-14  |  2.6 KB  |  132 lines  |  [TEXT/KAHL]

  1. #include <Types.h>
  2. #include <Memory.h>
  3. #include <QuickDraw.h>
  4. #include <OSUtils.h>
  5. #include <ToolUtils.h>
  6. #include <Menus.h>
  7. #include <Packages.h>
  8. #include <Traps.h>
  9. #include <Files.h>
  10. #include <Aliases.h>
  11. #include <AppleEvents.h>
  12. #include <GestaltEqu.h>
  13. #include <Processes.h>
  14. #include <Fonts.h>
  15. #include <OSEvents.h>
  16. #include <Resources.h>
  17. #include <Desk.h>
  18.  
  19. #include "standardgetfile.h"
  20. #include "boxmakergetfile.h"
  21.  
  22. #include "boxmaker constants.h"
  23. #include "boxmaker.h"
  24. #include "preferences.cp"
  25. #include "touchshell.h"
  26.  
  27. #pragma template_access public
  28.  
  29. void main();
  30.  
  31. void main()
  32. {
  33.     touchsettings defaultSettings =
  34.     {
  35.         touchshell::kSecondButton,
  36.         touchshell::kModDate
  37.     };
  38.     StringHandle prefsFileHandle = GetString( 128);
  39.     touchshell it( *(Str255 *)*prefsFileHandle, defaultSettings);
  40.     it.run();
  41. }
  42.  
  43. touchshell::touchshell( Str255 prefsFileName, touchsettings &defaultsettings)
  44.         : boxmaker( 3000)
  45.         , touchprefs( prefsFileName, defaultsettings)
  46. {    
  47.     Handle times = Get1Resource( 'tims', 128);
  48.     
  49.     MoveHHi( times);
  50.     HLock( times);
  51.     
  52.     theGrains = (long *)*times;
  53.     
  54.     GetDateTime( &starting_time);
  55.     ChangeGrain( whichGrain);
  56.     ChangeDate( whichDate);
  57. }
  58.  
  59. void touchshell::OpenDoc( Boolean opening)
  60. {
  61.     if( opening)
  62.     {
  63.         if( whichDate != kModDate)
  64.         {
  65.             theCInfoPBRec.hFileInfo.ioFlCrDat = time_to_set;
  66.         }
  67.         if( whichDate != kCreatDate)
  68.         {
  69.             theCInfoPBRec.hFileInfo.ioFlMdDat = time_to_set;
  70.         }
  71.         theCInfoPBRec.hFileInfo.ioFDirIndex = 0;
  72.         const OSErr result = PBSetCatInfoSync( &theCInfoPBRec);
  73.         if( result != noErr)
  74.         {
  75.             SysBeep( 9);
  76.         }
  77.     }
  78. }
  79.  
  80. void touchshell::HandleDialogEvent( short itemHit, DialogPtr theDialog)
  81. {
  82.     switch( itemHit)
  83.     {
  84.         case kSecondButton:
  85.         case kMinuteButton:
  86.         case kHourButton:
  87.         case kHalfDayButton:
  88.         case kDayButton:
  89.         case kGroundZeroButton:
  90.             ChangeGrain( itemHit);
  91.             break;
  92.             
  93.         case kCreatDate:
  94.         case kModDate:
  95.         case kBothDates:
  96.             ChangeDate( itemHit);
  97.             break;
  98.     }
  99. }
  100.  
  101. void touchshell::ChangeGrain( int newGrain)
  102. {
  103.     short    iType;
  104.     Handle    iHandle;
  105.     Rect    iRect;
  106.  
  107.     for( int i = kSecondButton; i <= kGroundZeroButton; i++)
  108.     {
  109.         GetDialogItem( gMainDialog, i, &iType, &iHandle, &iRect);
  110.         SetControlValue( (ControlHandle)iHandle, (i == newGrain));
  111.     }
  112.     whichGrain = newGrain;
  113.     const long granularity = theGrains[ whichGrain - 1];
  114.     
  115.     time_to_set = granularity *
  116.         ((starting_time + granularity - 1) / granularity);
  117. }
  118.  
  119. void touchshell::ChangeDate( int newDate)
  120. {
  121.     short    iType;
  122.     Handle    iHandle;
  123.     Rect    iRect;
  124.  
  125.     for( int i = kCreatDate; i <= kBothDates; i++)
  126.     {
  127.         GetDialogItem( gMainDialog, i, &iType, &iHandle, &iRect);
  128.         SetControlValue( (ControlHandle)iHandle, (i == newDate));
  129.     }
  130.     whichDate = newDate;
  131. }
  132.